﻿using System;
using System.Collections.Generic;
using Luna.Data.Security.Mappers;

namespace Luna.Data.Security
{
    public class SecurityDataProvider : LunaDataProvider, ISecurityDataProvider
    {
        public SecurityDataProvider()
        {
            DefineTypeCreation<IUserData, UserData>();
        }

        public UserDataMapper UserMapper { get; set; }

        private const string NAME = "Luna security data provider";
        private const string _ID = "{3DD5BE5E-AACC-41E9-9936-F650B62F014C}";

        public override Guid ID
        {
            get { return new Guid(_ID); }
        }

        public override string Name
        {
            get { return NAME; }
        }

        public IEnumerable<IUserData> GetAllUsers()
        {
            return WrapperTransactional(T => UserMapper.GetAll(T));
        }

        public IUserData GetUser(Guid P_UserID)
        {
            return WrapperTransactional(T => UserMapper.Get(T, P_UserID));
        }

        public IUserData GetUser(string P_UserLogin)
        {
            return WrapperTransactional(T => UserMapper.GetByLogin(T, P_UserLogin));
        }

        public void SaveUser(IUserData P_User)
        {
            WrapperTransactional(T => UserMapper.Save(T, P_User));
        }

        public void DeleteUser(Guid P_UserID)
        {
            WrapperTransactional(T => UserMapper.Delete(T, P_UserID));
        }
    }
}
